import { CopyInfoPanelBase } from "../CopyInfoPanelBase";
import { ObjCreate } from "../../common/ObjCreate";
import { TextAlign } from "../../../../../flashx/textLayout/formats/TextAlign";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { Language } from "../../../../../extend/language/Language";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { BossConfig } from "../../../resource/BossConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SCopyMaterialInfo } from "../../../../../Message/Public/SCopyMaterialInfo";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { SecTimerView } from "../../common/SecTimerView";
type int = number;
//class MaterialCopyInfoPanel
    
    export  class MaterialCopyInfoPanel extends CopyInfoPanelBase
    {
        constructor()
        {
            super();
            this._itemArray = [];
            this._passTxtArray = [];
            this._passNameArray = [];
            this._bossCodes = [];
            this.initView();
            updatePosition();
            _bg.height = 250;
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            var loc3=null;
            var loc5=null;
            var loc7=null;
            var loc8=null;
            this._txtTitle = ObjCreate.createGTextField("", 0, 10, 260, 20, _bodySp);
            loc1 = this._txtTitle.defaultTextFormat;
            loc1.align = TextAlign.CENTER;
            this._txtTitle.defaultTextFormat = loc1;
            this._conditionPanel = new Object /* flash.display.Sprite */();
            this._conditionPanel.x = 0;
            this._conditionPanel.y = 12;
            _bodySp.addChild(this._conditionPanel);
            var loc2=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            loc3 = ObjCreate.createGTextField(Language.getString(50030), 10, 10, 200, 20, this._conditionPanel, loc2);
            var loc4=new GTextFormat(FontUtil.songtiName, 18, 65280, true);
            this._timeView = ObjCreate.createSecTimeView("mm: ss", 0, 27, 260, 20, this._conditionPanel, loc4);
            this._timeView.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createGTextField(Language.getString(60360), 10, 50, 200, 20, this._conditionPanel);
            var loc6=0;
            while (loc6 < 4) 
            {
                (loc5 = ObjCreate.createGTextField("", 10, 70 + loc6 * 20, 200, 20, this._conditionPanel)).autoSize = flash.text.TextFieldAutoSize.LEFT;
                this._passTxtArray.push(loc5);
                ++loc6;
            }
            ObjCreate.createBg(5, 150, 245, 2, this._conditionPanel, ImagesConst.SplitLine);
            this._rewardsPanel = new Object /* flash.display.Sprite */();
            this._rewardsPanel.x = 0;
            this._rewardsPanel.y = 160;
            _bodySp.addChild(this._rewardsPanel);
            ObjCreate.createGTextField(Language.getString(36293), 10, 8, 200, 20, this._rewardsPanel, GlobalStyle.textFormat6);
            var loc9=0;
            while (loc9 < 4) 
            {
                loc8 = ObjCreate.createBg(50 + loc9 % 4 * 45, 30 + Math.floor(loc9 / 4) * 45, 38, 38, this._rewardsPanel, ImagesConst.PackItemBg);
                (loc7 = new BaseItem()).setSize(32, 32);
                loc7.x = loc8.x + 3;
                loc7.y = loc8.y + 3;
                this._rewardsPanel.addChild(loc7);
                this._itemArray.push(loc7);
                ++loc9;
            }
            return;
        }

        /* internal  */updateReward(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._itemArray.length) 
            {
                loc1 = this._itemArray[loc2] as BaseItem;
                loc1.itemData = new ItemData(int(arg1[loc2]));
                ++loc2;
            }
            return;
        }

        /* internal  */updatePassCondition(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            if (this._bossCodes.length == this._passTxtArray.length) 
            {
                loc4 = 0;
                while (loc4 < this._passTxtArray.length) 
                {
                    loc2 = BossConfig.instance.getInfoByName(this._bossCodes[loc4]);
                    loc1 = this._passTxtArray[loc4];
                    loc3 = Language.getStringByParam(58007, loc2.name);
                    loc1.text = loc3;
                    if (this._passNameArray.length < 4) 
                    {
                        this._passNameArray.push(loc3);
                    }
                    ++loc4;
                }
            }
            this.dispatchGuildexit();
            return;
        }

        /* internal  */dispatchGuildexit(): void
        {
            var loc1=false;
            var loc2=0;
            if (this._info && this._info.bossCodes.length == this._bossCodes.length) 
            {
                loc1 = true;
                loc2 = 0;
                while (loc2 < this._info.bossCodes.length) 
                {
                    if (this._bossCodes.indexOf(this._info.bossCodes[loc2]) == -1) 
                    {
                        loc1 = false;
                    }
                    ++loc2;
                }
                if (loc1) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ClickCopyExit));
                }
            }
            return;
        }

        public updateByTempleInfo(arg1: SCopyMaterialInfo): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            this._info = arg1;
            if (this._info) 
            {
                this._timeView.setLeftTime(this._info.remainTime);
                var loc4=0;
                var loc5=this._info.bossCodes;
                for(loc1 of loc5) 
                {
                    loc2 = 0;
                    while (loc2 < this._bossCodes.length) 
                    {
                        if (loc1 == this._bossCodes[loc2]) 
                        {
                            if (loc3 = this._passTxtArray[loc2]) 
                            {
                                loc3.htmlText = this._passNameArray[loc2] + "    " + Language.getString(58009);
                            }
                        }
                        ++loc2;
                    }
                }
                this.dispatchGuildexit();
            }
            return;
        }

        /* internal  */updateBossCode(arg1: int): void
        {
            if (arg1 != 428) 
            {
                if (arg1 == 429) 
                {
                    this._bossCodes = [2429200, 2429201, 2429202, 2429203];
                }
            }
            else 
            {
                this._bossCodes = [2428200, 2428201, 2428202, 2428203];
            }
            this.updatePassCondition();
            return;
        }

        public updateByCopyInfo(arg1: TCopy): void
        {
            if (arg1) 
            {
                _titleSp.title = HTMLUtil.addColor(arg1.name, GlobalStyle.color2);
                this._timeView.setLeftColor(300, "#ff0000");
                if (arg1.reward && !(arg1.reward == "0") && !(arg1.reward == "")) 
                {
                    this.updateReward(arg1.reward.split(","));
                }
                this.updateBossCode(arg1.copyId);
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show();
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._info = null;
            return;
        }

        /* internal */ /* var */_txtTitle: GTextFiled;

        /* internal */ /* var */_timeView: SecTimerView;

        /* internal */ /* var */_conditionPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_itemArray: Array<any>;

        /* internal */ /* var */_rewardsPanel: Object /* flash.display.Sprite */;

        /* internal */ /* var */_passTxtArray: Array<any>;

        /* internal */ /* var */_passNameArray: Array<any>;

        /* internal */ /* var */_bossCodes: Array<any>;

        /* internal */ /* var */_info: SCopyMaterialInfo;
    }
